package com.yf.user.controller;

import com.yf.user.pojo.DrUserDTO;
import com.yf.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;

@Api(value = "user", tags = "UserServiceApi", description = "用户服务接口")
@Slf4j
@RequestMapping(value = "user", produces = {APPLICATION_JSON_UTF8_VALUE})
@RestController
public class UserController {

    @Autowired private UserService userService;

    @ApiOperation(value = "根据userId获取用户信息", response = ResponseEntity.class)
    @ApiResponses(value = {
            @ApiResponse(code = 400, message = "指定id的用户不存在", response = String.class),
            @ApiResponse(code = 401, message = "请获得授权", response = String.class),
            @ApiResponse(code = 403, message = "禁止访问信息", response = String.class),
            @ApiResponse(code = 500, message = "请联系管理员", response = String.class)
    })
    @RequestMapping(value = "{uid}", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity getMemberByUid(@PathVariable int uid) {
        log.info( " See log file --- uid is: {}", uid);

        DrUserDTO dto = userService.getDrUserDTOByUid(uid);

        return ResponseEntity.ok(dto);
    }

}
